package com.mkvld.appietijdenv2.data;

import java.io.Serializable;

public class Budget implements Serializable {
	private static final long serialVersionUID = 8482507527470244706L;
	public static final int TYPE_VACATION = 0;
	public static final int TYPE_ADV = 1;
	public static final int TYPE_TVT = 2;
	int type;
	double budget, breeded, withdrawn, nextYear;
	
	public Budget(int type, double budget, double breeded, double withdrawn, double nextYear) {
		this.type = type;
		this.budget = budget;
		this.breeded = breeded;
		this.withdrawn = withdrawn;
		this.nextYear = nextYear;
	}
	
	public Budget(Budget other) {
		type = other.type;
		budget = other.budget;
		breeded = other.breeded;
		withdrawn = other.withdrawn;
		nextYear = other.nextYear;
	}

	public double getBudget() {
		return budget;
	}
	public double getBreeded() {
		return breeded;
	}
	public double getWithdrawn() {
		return withdrawn;
	}
	public double getNextYear() {
		return nextYear;
	}
	public double getToBreed(int period, int contract) {
		switch (type) {
		case TYPE_VACATION:
			return (period < 6) ? (6 - period) * 1.2 / 13 * contract : 0; 
		case TYPE_ADV:
			return (12 - period) * 0.075 * contract;
		case TYPE_TVT:
			return 0;
		default:
			return -1;
		}
	}
	
	public double getTotal(int period, int contract) {
		return budget + breeded + getToBreed(period, contract);
	}
	public double getWithdrawable(int period, int contract) {
		return getTotal(period, contract) - withdrawn;
	}

	public void next(int newPeriod, double withdrawn, double payed, int contract) {
		if (newPeriod == 0) {
			budget = getWithdrawable(12, contract) + nextYear;
			breeded = 0;
			withdrawn = 0;
			nextYear = 0;
		}
		this.withdrawn += withdrawn;
		switch (type) {
		case TYPE_VACATION:
			if (newPeriod > 6)
				nextYear += (double)192 / 13 * payed / 160;
			else
				breeded += (double)192 / 13 * payed / 160;
			break;
		case TYPE_ADV:
			breeded += 156 / 13 * payed / 160;
			break;
		case TYPE_TVT:
			break;
		}
	}
}
